//
//  GestureLocMgr.m
//  carcareIOS
//
//  Created by 王然 on 16/7/21.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "GestureLocMgr.h"
#import "AIGestureLoc.h"

@interface GestureLocMgr()

@property (nonatomic , strong) NSDateFormatter * formatter;

@end

@implementation GestureLocMgr

IMP_SINGLETON

//设置行程页面这次显示手势密码的时间
- (void)setDriverPageGestureTime
{
    NSDate * date = [NSDate date];
    [self.formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSTimeInterval fiveMinet = 60 * 5 * 1;
    AIGESTURELOC.driverPageGestureTime = [self.formatter stringFromDate:[date dateByAddingTimeInterval:fiveMinet]];
}
//获取这次显示行程页面和上一次验证手势密码时间是否超过5分
- (BOOL)getDrivePageIsGesture
{
    [self.formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSDate * nowDate = [NSDate date];
    if ([AIGESTURELOC.driverPageGestureTime isNotNil] && NSOrderedDescending != [nowDate compare:[self.formatter dateFromString:AIGESTURELOC.driverPageGestureTime]] ) {
        
        return NO;
    }else
    {
        [GESTURELOCMGR setDriverPageGestureTime];
        return YES;
    }

}
//保存手势密码输入错误5次的时间
- (void)saveWrongFiveTime
{
    NSDate * date = [NSDate date];
    [self.formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSTimeInterval fiveMinet = 60 * 5 * 1;
    NSString * saveTime = [self.formatter stringFromDate:[date dateByAddingTimeInterval:fiveMinet]];
    AIGESTURELOC.savePWWrongTime = saveTime;
}
//返回是否已经超过了5分钟，是返回YES  否则NO
- (BOOL)loadSaveWrongTimeOutFiveMinute
{
    [self.formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate * saveDate = [self.formatter dateFromString:AIGESTURELOC.savePWWrongTime];
    
    NSDate * nowDate = [NSDate date];
    if (AIGESTURELOC.savePWWrongTime.length > 0 && NSOrderedDescending != [nowDate compare:saveDate] ) {
        return NO;
    }else
    {
        return YES;
    }
}
- (NSDateFormatter *)formatter
{
    if (!_formatter) {
        _formatter = [[NSDateFormatter alloc]init];
    }
    return _formatter;
}

@end
